package com.eastfair.mobile.service.impl;

//import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.mobile.service.MobileArrangementManageService;
import com.eastfair.venuebooking.api.ArrangementManageFeign;
import com.eastfair.venueservice.dto.ArrangementManageDTO;
import com.eastfair.venueservice.dto.ArrangementManagePageQuery;
import com.eastfair.venueservice.enumeration.ArrangementManageArrangementSourceEnum;
import com.eastfair.venueservice.vo.ArrangementManageVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 主场 布撤展管理 服务e.
 *
 * @Author lyw
 * @Date 2022 /9/13 20:25
 */
@Slf4j
@Service
//@DS("#thread.tenant")
public class MobileArrangementManageServiceImpl implements MobileArrangementManageService {

    @Resource
    private ArrangementManageFeign arrangementManageFeign;

    @Override
    public Page<ArrangementManageVO> queryArrangementManageList(PageParams<ArrangementManageDTO> params) {
        log.info("queryArrangementManageList - 查询布撤展管理列表分页, params={}", params);
        ArrangementManageDTO model = params.getModel();
        List<ArrangementManageArrangementSourceEnum> arrangementSourceEnums = new ArrayList<>();
        arrangementSourceEnums.add(ArrangementManageArrangementSourceEnum.HOME_CHECK);
        model.setArrangementSourceList(arrangementSourceEnums);
        R<Page<ArrangementManageVO>> r = arrangementManageFeign.queryForHomeCheck(params);
        if (!r.getIsSuccess()) {
            throw BizException.wrap(r.getCode(), r.getMsg());
        }
        return r.getData();
    }

    @Override
    public ArrangementManageVO getArrangementManage(ArrangementManageDTO arrangementManageDTO) {
        log.info("getArrangementManage - 查询布撤展管理详情, arrangementManageDTO={}", arrangementManageDTO);
        R<ArrangementManageVO> r = arrangementManageFeign.getArrangementManage(arrangementManageDTO);
        if (!r.getIsSuccess()) {
            throw BizException.wrap(r.getCode(), r.getMsg());
        }
        return r.getData();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean saveArrangementManage(ArrangementManageDTO arrangementManageDTO) {
        log.info("saveArrangementManage - 保存布撤展管理, arrangementManageDTO={}", arrangementManageDTO);
        R<Boolean> r = arrangementManageFeign.submitForHomeCheck(arrangementManageDTO);
        if (!r.getIsSuccess()) {
            throw BizException.wrap(r.getCode(), r.getMsg());
        }
        return r.getData();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateArrangementManage(ArrangementManageDTO arrangementManageDTO) {
        log.info("updateArrangementManage - 修改布撤展管理, arrangementManageDTO={}", arrangementManageDTO);
        R<Boolean> r = arrangementManageFeign.updateArrangementManage(arrangementManageDTO);
        if (!r.getIsSuccess()) {
            throw BizException.wrap(r.getCode(), r.getMsg());
        }
        return r.getData();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean delArrangementManage(Long id) {
        log.info("delArrangementManage - 删除布撤展, id={}", id);
        R<Boolean> r = arrangementManageFeign.delArrangementManage(id);
        if (!r.getIsSuccess()) {
            throw BizException.wrap(r.getCode(), r.getMsg());
        }
        return r.getData();
    }
}
